s = input()
mx = 0
a1 = [s[0], s[1], s[2], s[0:2], s[1:3], s[2:4], s[0:3], s[1:4], s]
for h in range(len(a1)):
    a = int(a1[h])
    c = 0
    for i in range(1, a+1):
        if a%i == 0:
            c = c+1
    if c == 2:
        mx = max(mx, a)
print(mx)
